#include <GameState.hpp>
#include <GameEngine.hpp>
#include <GameWorld.hpp>

namespace EE
{
	GameState::GameState(GameEngine *engine) :
		GameStateBase(engine)
	{
		world = new GameWorld(this);
	}

	void GameState::Process(sf::Event event)
	{
		switch (event.Type)
		{
			case sf::Event::Closed:
				game->Stop();
				break;
			default:
				break;
		}
	}

	void GameState::Update()
	{
	}

	void GameState::UpdateTimed(unsigned long time)
	{
		if (isPaused)
		{
			pausedTime += pausedTimer.GetElapsedTime();
			pausedTimer.Reset();
		}
		else
		{
			elapsedTime += elapsedTimer.GetElapsedTime();
			elapsedTimer.Reset();
		}
		if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
		{
			world->MoveLeft(time);
		}
		if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
		{
			world->MoveRight(time);
		}
		if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))
		{
			world->MoveUp(time);
		}
		if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))
		{
			world->MoveDown(time);
		}
	}

	void GameState::Render()
	{
		game->window->Draw(world->GetSprites());
	}
}
